classdef FeatureSelection ...
        < Algorithm ...
        & FeatureSubsetSizeable ...
        & Modelable
    %FEATURESELECTION Summary of this class goes here
    %   Detailed explanation goes here
    
    properties ( SetAccess = protected )
        direction = 'backward' % 'forward'/1 'backward'/-1
    end
    
    methods
        function [  ] = setDirection( this, direction )
            if nargin == 2
                this.direction = direction;
            end
        end
    end
    
    methods
        function [ this ] = FeatureSelection(  )
        end
    end
    
    methods
%         function [  ] = valid( this, X, Y, algorithm )
%             
%             zSubsetSize = this.calcFeatureSubsetSamplingSizeOn( this, X );
%             nSubsetSize = length(zSubsetSize);
%             
%             zValidMetric = nan(1, nSubsetSize);
%             for iSubsetSize = 1:nSubsetSize
%                 X_i = X(:, this.model.zRank(1:zSubsetSize(iSubsetSize)));
%                 algorithm.build(X_i, Y);
%                 algorithm.apply
%             end
%         end
        
        function [ result ] = apply( this, X2, Y2, kFeature )
            % Return the selected feature subsets
            
            if nargin == 4
                if isfield(this.model, 'zFullRank')
                    result = X2(:, this.model.zFullRank(1:kFeature));
                    return
                end
            elseif isfield(this.model, 'kFeature')
                kFeature = this.model.kFeature;
            else
                kFeature = min(this.calcFeatureSubsetSizeOn(X2), length(this.model.zRank));
            end
            if length(this.model.zRank) < kFeature && isfield(this.model, 'zFullRank')
                result = X2(:, this.model.zFullRank(1:kFeature));
            else
                result = X2(:, this.model.zRank(1:kFeature));
            end
        end
    end
    
end

